home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
program
/
snip9611.zip
/
STRREV.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-24
|
849b
|
50 lines
/* +++Date last modified: 24-Nov-1996 */
/*
** STRREV.C - reverse a string in place
**
** public domain by Bob Stout
*/
#include <string.h>
#include "snip_str.h"
#if defined(__cplusplus) && __cplusplus
extern "C" {
#endif
char *strrev(char *str)
{
char *p1, *p2;
if (! str || ! *str)
return str;
for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
{
*p1 ^= *p2;
*p2 ^= *p1;
*p1 ^= *p2;
}
return str;
}
#if defined(__cplusplus) && __cplusplus
}
#endif
#ifdef TEST
#include <stdio.h>
int main(int argc, char *argv[])
{
while (--argc)
{
printf("\"%s\" backwards is ", *++argv);
printf("\"%s\"\n", strrev(*argv));
}
return 0;
}
#endif /* TEST */